﻿using Ross.Service;
using Ross.Service.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Http.Controllers;
using Ross.EntityFramework.Model;
using Ross.EntityFramework;

namespace Ross.Traning.Controllers
{
    [SimpleAuthenticationFilter]
    public class FAQsController:BaseApiController
    {
        [HttpPost]
        public JsonResult<ResultDto<bool>> Insert([FromBody] Service.Dto.FAQs vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (FAQsService serv = new FAQsService(dbContextStr))
            {
                result = serv.Create(vm);
            }
            return Json(result);
        }
        [HttpPost]
        public JsonResult<ResultDto<bool>> Update([FromBody] Service.Dto.FAQs vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (FAQsService serv = new FAQsService(dbContextStr))
            {
                result = serv.Update(vm);
            }
            return Json(result);
        }
        [HttpPost]
        public JsonResult<ResultDto<bool>> Answer([FromBody] Service.Dto.AnswerObj vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (FAQsService serv = new FAQsService(dbContextStr))
            {
                result = serv.Answer(vm.ID, vm.AnswerContent);
            }
            return Json(result);
        }

        [HttpPost]
        public JsonResult<ResultDto<bool>> Delete(int id)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (FAQsService serv = new FAQsService(dbContextStr))
            {
                result = serv.Delete(id);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.FAQs>>> GetList(int pageindex = 1, int pagesize = 10, long userId = 0, long teacherId = 0, string keywords = "",int isCLosed = -1)
        {
            ResultDto<List<Service.Dto.FAQs>> result = new ResultDto<List<Service.Dto.FAQs>>();
            using (FAQsService serv = new FAQsService(dbContextStr))
            {
                result = serv.GetPageList(pageindex, pagesize, userId, teacherId, keywords, isCLosed);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<Service.Dto.FAQs>> GetByID( int id)
        {
            ResultDto<Service.Dto.FAQs> result = new ResultDto<Service.Dto.FAQs>();
            using (FAQsService serv = new FAQsService(dbContextStr))
            {
                result = serv.GetByID(id);
            }
            return Json(result);
        }
    }
}